package com.langfeiyes.pattern.memento.demo;

/**
 * 原发器：
 * 创建备忘录的地方
 * 触发保存备忘对象的地方
 */
public class Originator {
    private String state;  //初始化状态
    //创建备忘录
    public IMemento createMemento(){
        return new MementoImpl(this.state);
    }


    //恢复Originator 原发器状态
    public void setMemento(IMemento memento){
        MementoImpl mi = (MementoImpl) memento;
        this.state = mi.state;
    }


    //备忘录实现对象，里面属性跟Originator 一样，用于缓存Originator对象状态
    private  class  MementoImpl implements IMemento{
        private String state;
        @Override
        public void info() {
            System.out.println("备忘录状态：" + state);
        }

        public MementoImpl(String state){
            this.state = state;
        }
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getState() {
        return state;
    }
}
